package com.example.demo.leetcode.top100;

/**
 * ******************************************************
 *
 * @author liugh9
 * @version 1.0
 * @classname _83打家劫舍
 * @description
 * @date 2023/06/29 10:35
 * <p>
 * ******************************************************
 */
public class _83打家劫舍 {
    public int rob(int[] nums) {
        int length = nums.length;
        if (length==1) return nums[0];
        int[] dp = new int[length];
        // 1代表偷
        dp[0] = nums[0];
        dp[1] = Math.max(nums[0], nums[1]);
        for (int i = 2; i < length; i++) {
            dp[i] = Math.max(dp[i-1], dp[i-2] + nums[i]);
        }
        return dp[length-1];
    }
}
